/**
 * Zhz.net Inc.
 * Copyright (c) 2004-2010 All Rights Reserved.
 */
package com.zhz.lib.project.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.zhz.lib.project.controller.form.FaqForm;
import com.zhz.lib.project.domain.news.Sortmap;
import com.zhz.lib.project.service.faq.FaqService;
import com.zhz.project.common.util.ibatispage.IbatisPage;
import com.zhz.project.common.util.zhzutil.ZhzBeanUtils;
import com.zhz.project.common.util.zhzutil.ZhzHttpRequestUtil;

/**
 * 
 * @author Administrator
 * @version $Id: FaqController.java, v 0.1 Sep 16, 2010 7:55:57 AM Administrator
 *          Exp $
 */

@Controller
@RequestMapping("/faq.do")
public class FaqController {
    private static Logger logger   = Logger.getLogger(FaqController.class);
    @Autowired
    private FaqService    faqService;
    @Autowired
    private IbatisPage    ibatisPage;

    private static String pageSql  = "selectAllFaqByPage";
    private static String countSql = "selectAllFaqCount";

    @RequestMapping(method = RequestMethod.POST)
    public String getIbatisListPostNoAction(ModelMap model, FaqForm faqForm) {
        return page(model, faqForm);
    }

    @RequestMapping(method = RequestMethod.GET)
    public String getIbatisListGetNoAction(ModelMap model, FaqForm faqForm) {
        return page(model, faqForm);
    }

    @RequestMapping(method = RequestMethod.POST, params = "action=page")
    public String getIbatisListPost(ModelMap model, FaqForm faqForm) {
        return page(model, faqForm);
    }

    @RequestMapping(method = RequestMethod.GET, params = "action=page")
    public String getIbatisListGet(ModelMap model, FaqForm faqForm) {
        return page(model, faqForm);
    }

    @SuppressWarnings("unchecked")
    private String page(ModelMap model, FaqForm faqForm) {
        ZhzHttpRequestUtil.writeMapToModelMap(model, ibatisPage.getPage(ZhzBeanUtils
            .describe(faqForm), countSql, pageSql));

        // 获取常见问题类型
        List<Sortmap> typeList = faqService.getFaqType();
        model.put("typeList", typeList);

        return "faq";
    }

    /**
     * 
     * 根据id获取常见问题
     * 
     * @param model
     * @param request
     * @param response
     * @param id
     * @return
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(method = RequestMethod.GET, params = "event=single")
    public String getSingleNews(ModelMap model, HttpServletRequest request,
                                HttpServletResponse response, @RequestParam("id") int id) {
        model.put("faq", faqService.getFaqById(id));
        return "faqDetail";
    }

}
